IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'CreatorGetByUserName')
	BEGIN
		DROP  Procedure  CreatorGetByUserName
	END

GO

CREATE Procedure CreatorGetByUserName
@UserName varchar(50)
AS
Select 
c.CreatorID,
c.DefaultSagaID,
c.IsBrowser,
c.CanAdd,
asp.UserName,
coalesce (r.RoleName,'Browser') RoleName,
coalesce (r.SagaRoleID,0) SagaRoleID
From Creator c
Join aspnet_Users asp On asp.UserID = c.UserID
Left Join  aspnet_UsersInRoles ri On ri.UserID = asp.UserID
Left Join SagaCreators sc On sc.CreatorID = c.CreatorID and sc.SagaId = c.DefaultSagaID
Left Join SagaRoles r on r.SagaRoleID = sc.SagaRoleID 
Where asp.UserName = @UserName
